import json
import requests

def call_preprocess_and_tran():
    url = "http://127.0.0.1:18180/v1/preprocess_and_tran"

    payload = {
        "format": "wav",
        "reference_audio": "nihao.wav",  # 替换为实际路径
        "lang": "zh"
    }
    response = requests.post("http://127.0.0.1:18180/v1/preprocess_and_tran", json=payload)

    print("📤 请求体 JSON:")
    print(json.dumps(payload, indent=2, ensure_ascii=False))  # 打印出漂亮格式

    try:
        response.raise_for_status()
    except requests.exceptions.HTTPError as e:
        print("❌ 请求失败:", e)
        print("📥 错误内容:")
        try:
            print(json.dumps(response.json(), indent=2, ensure_ascii=False))
        except Exception:
            print(response.text)
# 调用
asr_url, ref_text = call_preprocess_and_tran()